package indi.mumu.common.controller;

import indi.mumu.common.model.Clothes;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import indi.mumu.interceptor.POSInterceptor;
import indi.mumu.validator.POSValidator;

@Before(POSInterceptor.class)
public class POSController extends Controller {
	public void index() {
		setAttr("clothesPage", Clothes.dao.paginate(getParaToInt(0, 1), 10, "select *","from Clothes"));
		render("pos.html");
	}
	
	public void add() {
	}
	
	@Before(POSValidator.class)
	public void save() {
		getModel(Clothes.class).save();
		redirect("/pos");
	}
	
	public void edit() {
		setAttr("clothes", Clothes.dao.findById(getParaToInt()));
	}
	
	@Before(POSValidator.class)
	public void update() {
		getModel(Clothes.class).update();
		redirect("/pos");
	}
	
	public void delete() {
		Clothes.dao.deleteById(getParaToInt());
		redirect("/pos");
	}
	
	public void query() {
		String key = getPara("key");
		setAttr("clothesPage", Clothes.dao.paginate(getParaToInt(0, 1), 10, "select *", "from clothes where name like'%"+ key+ "%'"));
		render("pos.html");
	}
}


